//
 

#import "NT_EditCategoryTableViewCell.h"

@implementation NT_EditCategoryTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //
        self.img = ({
            UIImageView *img = [[UIImageView alloc]init];
            [self.contentView addSubview:img];
            img;
        });
        self.titleLabel =  ({
            UILabel *label = [[UILabel alloc]init];
            label.textColor = rgba(90, 90, 90, 1);
            label.font = FontPFRegular(kRelativeWidth(15));
            label.text = @"";
            [self.contentView addSubview:label];
            label;
        });
        self.deleteBtn =  ({
            UIButton *button = [[UIButton alloc]init];
            [button setImage:[UIImage imageNamed:@"delete2"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(Action) forControlEvents:UIControlEventTouchUpInside];
            [self.contentView addSubview:button];
            button;
        });
        
    }
    return self;
}
//
- (void)setNeedsLayout {
    [super setNeedsLayout];
    
    [self.img mas_makeConstraints:^(MASConstraintMaker *make) {
         make.centerY.mas_equalTo(self.contentView);
        make.left.mas_offset(kRelativeWidth(12));
        make.width.height.mas_equalTo(kRelativeWidth(30));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.img);
        make.left.mas_equalTo(self.img.mas_right).offset(kRelativeWidth(20));
        make.height.mas_equalTo(kRelativeHeight(20));
    }];
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.titleLabel);
        make.right.mas_offset(-kRelativeWidth(20));
        make.width.height.mas_equalTo(kRelativeHeight(30));
    }];
    
}
//
- (void)Action {
    if ([self.delegate respondsToSelector:@selector(sendCellData:)]) {
        [self.delegate sendCellData:self];
    }
}

- (void)setModel:(NoteCategory *)model {
    _model = model;
    self.img.image = (UIImage*)model.picture;
    self.titleLabel.text = model.title;
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
